package com.md.value;

import com.md.base.EnumBase;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author 刘骄阳
 * 2022-09-22 21:42
 */
@Getter
@AllArgsConstructor
public enum UsersPermissionEnum implements EnumBase {
  /**
   * 有权限
   */
  HAS_PERMISSION(0, "HAS_PERMISSION"),

  /**
   * 无权限
   */
  UN_PERMISSION(1, "UN_PERMISSION");

  static final Map<Integer, UsersPermissionEnum> ENUM_MAP = Arrays.stream(UsersPermissionEnum.values())
    .collect(Collectors.toMap(UsersPermissionEnum::getCode, e -> e));

  static final Map<String, UsersPermissionEnum> ENUM_MAP_STRING = Arrays.stream(UsersPermissionEnum.values())
    .collect(Collectors.toMap(UsersPermissionEnum::getMessage, e -> e));
  private final Integer code;
  private final String message;

  public static UsersPermissionEnum of(final Integer code) {
    return ENUM_MAP.get(code);
  }

  /**
   * 根据值获取对应的枚举
   *
   * @param message code 值
   * @return 枚举对应的值
   */
  public static EnumBase of(final String message) {
    return ENUM_MAP_STRING.get(message);
  }


}
